package cn.zwk.drawing.domain.rendering.model;

import lombok.Data;
import lombok.Builder;

/**
 * 节点几何信息
 */
@Data
@Builder
public class NodeGeometry {
    
    /**
     * 节点ID
     */
    private String nodeId;
    
    /**
     * 节点名称
     */
    private String nodeName;
    
    /**
     * X坐标
     */
    private Double x;
    
    /**
     * Y坐标
     */
    private Double y;
    
    /**
     * 宽度
     */
    private Double width;
    
    /**
     * 高度
     */
    private Double height;
    
    /**
     * 中心点X坐标
     */
    private Double centerX;
    
    /**
     * 中心点Y坐标
     */
    private Double centerY;
    
    /**
     * SVG元素的CSS选择器
     */
    private String cssSelector;
    
    /**
     * 检查点是否在节点范围内
     */
    public boolean contains(double pointX, double pointY) {
        return pointX >= x && pointX <= x + width &&
               pointY >= y && pointY <= y + height;
    }
    
    /**
     * 计算到指定点的距离
     */
    public double distanceTo(double pointX, double pointY) {
        double dx = Math.abs(centerX - pointX);
        double dy = Math.abs(centerY - pointY);
        return Math.sqrt(dx * dx + dy * dy);
    }
    
    /**
     * 获取节点的边界框信息
     */
    public BoundingBox getBoundingBox() {
        return BoundingBox.builder()
                .minX(x)
                .minY(y)
                .maxX(x + width)
                .maxY(y + height)
                .build();
    }
}

/**
 * 边界框
 */
@Data
@Builder
class BoundingBox {
    private Double minX;
    private Double minY;
    private Double maxX;
    private Double maxY;
    
    public Double getWidth() {
        return maxX - minX;
    }
    
    public Double getHeight() {
        return maxY - minY;
    }
}